package com.woke.method;

import android.util.Log;
import android.view.View;
import android.widget.RelativeLayout;

import com.http.HttpMethods;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.woke.data.Datas_paytype;

import org.apache.http.Header;
import org.json.JSONException;
import org.json.JSONObject;

import org.greenrobot.eventbus.EventBus;

public class Httpgetpaytype {  
	private static String servifee = "f";
  
    public static String getbanked(final RelativeLayout mBar) { 
    	
    	AsyncHttpClient ahc = new AsyncHttpClient();
		RequestParams params = new RequestParams();
		params.put("g", "api");
		params.put("m", "pay");
		params.put("a", "getPayWay");
		ahc.get(HttpMethods.BASEURL, params, new JsonHttpResponseHandler(){
			@Override
		public void onSuccess(int statusCode, Header[] headers,
					JSONObject response) {
				super.onSuccess(statusCode, headers, response);
				Log.e("支付方式", ""+response);
				try {
					String flag = response.getString("flag");
					if(flag.equals("success")){
						JSONObject jsonObject = response.getJSONObject("data");
						String string = jsonObject.getString("data");
						Datas_paytype parseObject = com.alibaba.fastjson.JSONObject.parseObject(string, Datas_paytype.class);
//						ArrayList<Datas_paytype> parseArray = (ArrayList<Datas_paytype>) JSONArray.parseArray(string, Datas_paytype.class);
						EventBus.getDefault().post(parseObject);
					}else if(flag.equals("unknow")){
						Datas_paytype parseObject = com.alibaba.fastjson.JSONObject.parseObject("", Datas_paytype.class);
//						ArrayList<Datas_paytype> parseArray = (ArrayList<Datas_paytype>) JSONArray.parseArray("", Datas_paytype.class);
						EventBus.getDefault().post(parseObject);
					}
				} catch (JSONException e) {
					e.printStackTrace();
				}
			}
			
			@Override
			public void onFailure(int statusCode, Header[] headers,
					String responseString, Throwable throwable) {
				super.onFailure(statusCode, headers, responseString, throwable);
			}
			@Override
			public void onStart() {
				mBar.setVisibility(View.VISIBLE);
				super.onStart();
			}
			
			@Override
			public void onFinish() {
				mBar.setVisibility(View.GONE);
				super.onFinish();
			}
		});
		return servifee;
		
    }
}
